package com.houger.ddd.datamanager.operator;

import com.houger.ddd.datamanager.entity.InventoryId;
import com.houger.ddd.datamanager.utils.OperatorResult;
import org.apache.commons.beanutils.BeanUtils;

public interface InventoryOperator {

    default InventoryId getId(Object obj) {
        try {
            return new InventoryId(BeanUtils.getProperty(obj,"id"));
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }

    long getTotal(InventoryId id);

    long getUsed(InventoryId id);

    OperatorResult deduct(InventoryId id, long cnt);

    OperatorResult release(InventoryId id, long cnt);

    /**
     * cnt 会在 InventoryAspect 中从redis读取
     */
    boolean flushUsed(InventoryId id, long cnt);

}
